package com.sgl.gk.service.impl;


import com.sgl.common.core.domain.AjaxResult;
import com.sgl.gk.domain.GkEquipment;
import com.sgl.gk.mapper.GkEquipmentMapper;
import com.sgl.gk.scheduled.ScheduledTask;
import com.sgl.gk.service.GkEquipmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class GkEquipmentServiceImpl implements GkEquipmentService {

    @Autowired
    GkEquipmentMapper gkEquipmentMapper;

    @Override
    public List<GkEquipment> list(GkEquipment gkEquipment) {
        List<GkEquipment> gkEquipments = gkEquipmentMapper.list(gkEquipment);
        return gkEquipments;
    }

    @Override
    public AjaxResult add(GkEquipment gkEquipment) {
        Date date = new Date();
        gkEquipment.setCreateAt(date);
        gkEquipment.setLastModifyAt(date);
        int row = gkEquipmentMapper.add(gkEquipment);
        if (row>0){
            ScheduledTask.gkEquipmentList = gkEquipmentMapper.list(null);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @Override
    public AjaxResult edit(GkEquipment gkEquipment) {
        Date date = new Date();
        gkEquipment.setLastModifyAt(date);
        int row = gkEquipmentMapper.edit(gkEquipment);
        if (row>0){
            ScheduledTask.gkEquipmentList = gkEquipmentMapper.list(null);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    @Override
    public AjaxResult removeByIds(Long[] ids) {
        int row = gkEquipmentMapper.removeByIds(ids);
        if (row>0) {
            ScheduledTask.gkEquipmentList = gkEquipmentMapper.list(null);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}
